package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.game.Role;
import com.handinfo.android.game.item.Item;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.Prize;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlTools;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWGrid;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UIPrizeWindow implements IUIWindows {
	DWFrame m_prize_frame = null;
	Bitmap m_cr_tit = null;
	Bitmap m_cr_tuichu = null;
	Bitmap m_cr_but = null; // /按钮点击前图片
	Bitmap m_cr_but_1 = null;// /按钮点击后抬起前图片
	Bitmap m_cr_djs = null;
	Bitmap m_cr_down = null;
	Bitmap m_cr_xxbj = null;

	DWBackground m_xbj = null;
	DWImageBox m_tuichu = null;
	DWListbox m_zuo_listbox = null;
	DWListbox m_you_listbox = null;
	DWTextbox m_djs_tb = null;
	DWButton m_but = null;
	DWButton m_djs_but = null;

	/**
	 * 左侧相关
	 */
	// //左侧的颁奖列表listbox
	public DWTextbox m_list_text[];
	public DWBackground m_zuo_xxbj = null;
	/**
	 * 右侧相关
	 */
	public DWGrid m_item_up[];
	public DWTextbox m_item_num[];
	public DWTextbox m_data_tb;
	public DWBackground m_you_xxbj = null;

	public void Prize() {
		if (DWControlsManager.getInstance().contains(m_prize_frame)) {
			if (m_prize_frame != null) {
				DWControlsManager.getInstance().removeControl(m_prize_frame);
			}
		}
		// /画布、标题
		m_prize_frame = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		m_prize_frame.setClickClose(false);
		m_prize_frame.setThrough(true);
		DWControlsManager.getInstance().addControl(m_prize_frame);

		DWTitle m_tit = new DWTitle("", m_prize_frame);
		m_prize_frame.addControl(m_tit);
		DWImageBox m_tit_ima = new DWImageBox(m_cr_tit);
		m_tit_ima.setNearAnchor(m_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_prize_frame.addControl(m_tit_ima);

		// /退出
		m_tuichu = new DWImageBox(m_cr_tuichu);
		m_tuichu.setNearAnchor(m_tit, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER, 0, 0);
		m_tuichu.setTouchZoomIn(40, 40);
		m_tuichu.addListener(m_tuichu_lis);
		m_prize_frame.addControl(m_tuichu);

		// /小背景
		m_xbj = new DWBackground(m_prize_frame.getShowWidth() - 20, m_prize_frame.getShowHeight() - (m_tit.getShowHeight() - 20) - 20);
		m_xbj.setNearAnchor(m_prize_frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, (m_tit.getShowHeight() - 20) + 10);
		m_prize_frame.addControl(m_xbj);

		// //左侧相关
		m_zuo_xxbj = new DWBackground(m_cr_xxbj, (m_xbj.getShowWidth() - 30) / 3, m_xbj.getShowHeight() - 20);
		m_zuo_xxbj.setNearAnchor(m_xbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 10);
		m_prize_frame.addControl(m_zuo_xxbj);

		m_zuo_listbox = new DWListbox(m_zuo_xxbj.getShowWidth() - 20, m_zuo_xxbj.getShowHeight() - 20);
		m_zuo_listbox.setNearAnchor(m_zuo_xxbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 10);
		m_zuo_listbox.setLineSpacing(10);
		m_prize_frame.addControl(m_zuo_listbox);

		// 右侧相关
		m_you_xxbj = new DWBackground(m_cr_xxbj, m_xbj.getShowWidth() - 30 - m_zuo_xxbj.getShowWidth(), m_xbj.getShowHeight() - 20);
		m_you_xxbj.setNearAnchor(m_zuo_xxbj, Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 0);
		m_prize_frame.addControl(m_you_xxbj);

		m_you_listbox = new DWListbox(m_you_xxbj.getShowWidth() - 20, m_you_xxbj.getShowHeight() - m_cr_but.getHeight() - 15 - 15);
		m_you_listbox.setNearAnchor(m_you_xxbj, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 15);
		m_you_listbox.setShowBackgroundRect(false);
		m_prize_frame.addControl(m_you_listbox);

		// 领取按钮
		m_but = new DWButton("领取", m_cr_but);
		m_but.setDownImage(m_cr_but_1);
		m_but.setShow(false);
		m_but.setNearAnchor(m_you_xxbj, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -10, -10);
		m_but.addListener(m_but_lis);
		m_prize_frame.addControl(m_but);

		// /倒计时显示
		m_djs_tb = new DWTextbox("<mark c=FFBB11>" + "倒计时：" + "</mark>");
		m_djs_tb.setNearAnchor(m_you_xxbj, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 10, -10);
		m_djs_tb.setShow(false);
		m_prize_frame.addControl(m_djs_tb);
		DWGameManager.getInstance().getSendMessage().sendPrizeList();
	}

	public void init() {
		m_cr_tit = UIWindows.createImage("/img/newui/banjiang_1.gnp"); // //这里正常应该是颁奖2个字
		m_cr_tuichu = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");
		m_cr_but = UIWindows.createImage("/img/newui/anniu_6.gnp"); // //按钮的图片
		m_cr_but_1 = UIWindows.createImage("/img/newui/anniu_6ax.gnp"); // //按钮点击后变的图片
		m_cr_djs = UIWindows.createImage("/img/newui/fubenshenglidmk_1.gnp");// 倒计时
		m_cr_down = UIWindows.createImage("/img/newui/wupinlan.gnp");
		m_cr_xxbj = UIWindows.createImage("/img/newui/beibaobj_1.gnp");
	}

	public void open(byte index) {
		Prize();
	}

	public void close(byte index) {
	}

	public void dispose() {
	}

	public void logic() {
		Timer();
		DJS();
	}

	private DWListener m_tuichu_lis = new DWListener() {
		public void OnDoubleClick() {
		}

		public void OnClick() {
			DWControlsManager.getInstance().removeControl(m_prize_frame);
		}
	};

	private DWListener m_but_lis = new DWListener() {

		public void OnDoubleClick() {
		}

		public void OnClick() {
			if (m_flag) {
				if (m_prize_list.get(j).m_can_get == 1) {
					DWGameManager.getInstance().getSendMessage().sendPrizeApply(m_prize_list.get(j).m_key);
				}
				Tools.debugPrintln("j====" + j);
			} else if (!m_flag) {
				if (m_prize_list.get(m_zuo_listbox.getTouchIndex()).m_can_get == 1) {
					DWGameManager.getInstance().getSendMessage().sendPrizeApply(m_prize_list.get(m_zuo_listbox.getTouchIndex()).m_key);
				}
				Tools.debugPrintln("选中====" + m_zuo_listbox.getTouchIndex());
			}
		}
	};
	private long timer;
	private long m_start_time = 0;

	public void Timer() {
		if (DWControlsManager.getInstance().contains(m_prize_frame)) {
			if (timer > 0) {
				if (m_start_time == 0) {
					m_start_time = System.currentTimeMillis();// 读取时截取系统时间
				}
				long currentTime = System.currentTimeMillis();// 当前系统时间
				int index = (int) (timer - (currentTime - m_start_time) / 1000);
				if (index < 0) {
					m_start_time = 0;
				} else {
					int index_1 = index / 3600;
					int index_2 = index % 3600 / 60;
					int index_3 = index % 3600 % 60;
					if (index_1 != 0) {
						m_djs_tb.setText("<mark c=FFBB11>" + "倒计时: " + "</mark>" + "<mark c=FF3300>" + index_1 + "</mark>" + ":" + "<mark c=FF3300>" + index_2 + "</mark>" + ":" + "<mark c=FF3300>"
								+ index_3 + "</mark>");
					} else if (index_1 == 0) {
						if (index_2 != 0) {
							m_djs_tb.setText("<mark c=FFBB11>" + "倒计时: " + "</mark>" + "<mark c=FF3300>" + index_2 + "</mark>" + ":" + "<mark c=FF3300>" + index_3 + "</mark>");
						} else {
							m_djs_tb.setText("<mark c=FFBB11>" + "倒计时: " + "</mark>" + "<mark c=FF3300>" + index_3 + "</mark>");
						}
					}
					m_djs_tb.setShow(true);
					if (index == 0) {
						m_start_time = 0;
						timer = 0;
						// /这里可能是发送指令
						if (m_flag) {
							if (m_prize_list.get(j).m_timer > 0) {
								m_djs_tb.setShow(false);
								m_but.setShow(true);
								m_but.setTouch(true);
								m_but.setBackground(m_cr_but, false);
								m_but.setDownImage(m_cr_but_1);
							}
						} else if (!m_flag) {
							if (m_prize_list.get(m_zuo_listbox.getTouchIndex()).m_timer > 0) {
								m_djs_tb.setShow(false);
								m_but.setShow(true);
								m_but.setTouch(true);
								m_but.setBackground(m_cr_but, false);
								m_but.setDownImage(m_cr_but_1);
							}
						}
					}
				}
			}
		}
	}

	public void Item_infomation(int index) {
		// /发送查看道具的属性的指令
		if (m_flag) {
			DWGameManager.getInstance().getSendMessage().sendSeeItemInfos(0, m_prize_list.get(j).m_item_list[index].m_key);
			Tools.debugPrintln("j:" + j);
		} else if (!m_flag) {
			DWGameManager.getInstance().getSendMessage().sendSeeItemInfos(0, m_prize_list.get(m_zuo_listbox.getTouchIndex()).m_item_list[index].m_key);
			Tools.debugPrintln("m_zuo_listbox.getTouchIndex():" + m_zuo_listbox.getTouchIndex());
		}
	}

	public void Update(int m_index) {
		if (m_prize_list.get(m_index).itemsize > 0) {
			m_item_up = new DWGrid[m_prize_list.get(m_index).itemsize];
			m_item_num = new DWTextbox[m_prize_list.get(m_index).itemsize];
			// /取余数
			int m_num_1 = (m_you_listbox.getShowWidth() - 20) % (m_cr_down.getWidth() + 5);
			// 取整数
			int m_num_2 = (m_you_listbox.getShowWidth() - 20) / (m_cr_down.getWidth() + 5);

			if (m_num_1 < m_cr_but.getWidth()) {
				// for (int m_you_index = 0; m_you_index < (1 +
				// m_prize_list.get(m_index).moneysize + (m_prize_list
				// .get(m_index).itemsize + (m_num_2 - 1))
				// / m_num_2); m_you_index++) {
				for (int m_you_index = 0; m_you_index < (1 + m_prize_list.get(m_index).moneysize + 1); m_you_index++) {
					DWListSubItem m_lsi = new DWListSubItem();
					if (m_you_index == 0) {
						m_data_tb = new DWTextbox("<mark c=FFBB11>" + "规则：" + "</mark>" + DWControlTools.CHANGE_ROW + m_prize_list.get(m_index).m_desc + DWControlTools.CHANGE_ROW + "<mark c=55FF00>"
								+ "奖励：" + "</mark>", m_you_listbox.getShowWidth());
						m_data_tb.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
						m_lsi.addControls(m_data_tb);
					} else if (m_you_index > 0 && m_you_index < (1 + m_prize_list.get(m_index).moneysize)) {
						DWTextbox m_tb = new DWTextbox("<mark c=55FF00>" + "奖励" + "</mark>", m_you_listbox.getShowWidth());
						m_tb.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
						if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_BANGGONG) {
							m_tb.setText("<mark c=FFBB11>" + "帮贡：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_GOLD) {
							m_tb.setText("<mark c=FFBB11>" + "金币：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_JINGHUN) {
							m_tb.setText("<mark c=FFBB11>" + "惊魂：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_RMB) {
							m_tb.setText("<mark c=FFBB11>" + "元宝：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_RONGYU) {
							m_tb.setText("<mark c=FFBB11>" + "荣誉：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_XIUWEI) {
							m_tb.setText("<mark c=FFBB11>" + "修为：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_ZHANGONG) {
							m_tb.setText("<mark c=FFBB11>" + "战功：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						}
						m_lsi.addControls(m_tb);
					} else {
						for (int index = 0; index < m_prize_list.get(m_index).itemsize; index++) {
							m_item_up[index] = new DWGrid(m_cr_down);
							m_item_up[index].m_data = m_prize_list.get(m_index).m_item_list[index];
							m_item_num[index] = new DWTextbox(Integer.toString(m_prize_list.get(m_index).m_item_list[index].m_num));
							final int m_item_index = index;
							m_item_up[index].addListener(new DWListener() {

								public void OnDoubleClick() {
								}

								public void OnClick() {
									Item_infomation(m_item_index);
								}
							});
							if (index % m_num_2 == 0) {
								if (index == 0) {
									m_item_up[index].setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 0);
								} else {
									m_item_up[index].setNearAnchor(m_item_up[index - m_num_2], Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 5);
								}
							} else {
								m_item_up[index].setNearAnchor(m_item_up[index - 1], Tools.LEFT_TOP, Tools.RIGHT_TOP, 5, 0);
							}
							m_item_num[index].setNearAnchor(m_item_up[index], Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, 0, 0);
							m_item_num[index].setTouch(false);
							m_lsi.addControls(m_item_up[index]);
							m_lsi.addControls(m_item_num[index]);
						}
					}
					m_you_listbox.addSubItem(m_lsi);
				}
			} else {
				// for (int m_you_index = 0; m_you_index < (1 +
				// m_prize_list.get(m_index).moneysize + (m_prize_list
				// .get(m_index).itemsize + (m_num_2 + 1 - 1))
				// / (m_num_2 + 1)); m_you_index++) {
				for (int m_you_index = 0; m_you_index < (1 + m_prize_list.get(m_index).moneysize + 1); m_you_index++) {
					DWListSubItem m_lsi = new DWListSubItem();
					if (m_you_index == 0) {
						DWTextbox m_data_tb = new DWTextbox("<mark c=FFBB11>" + "规则：" + "</mark>" + DWControlTools.CHANGE_ROW + m_prize_list.get(m_index).m_desc + DWControlTools.CHANGE_ROW
								+ "<mark c=55FF00>" + "奖励：" + "</mark>", m_you_listbox.getShowWidth());
						m_data_tb.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
						m_lsi.addControls(m_data_tb);
					} else if (m_you_index > 0 && m_you_index < (1 + m_prize_list.get(m_index).moneysize)) {
						DWTextbox m_tb = new DWTextbox("<mark c=55FF00>" + "奖励" + "</mark>", m_you_listbox.getShowWidth());
						m_tb.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
						if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_BANGGONG) {
							m_tb.setText("<mark c=FFBB11>" + "帮贡：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_GOLD) {
							m_tb.setText("<mark c=FFBB11>" + "金币：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_JINGHUN) {
							m_tb.setText("<mark c=FFBB11>" + "惊魂：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_RMB) {
							m_tb.setText("<mark c=FFBB11>" + "元宝：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_RONGYU) {
							m_tb.setText("<mark c=FFBB11>" + "荣誉：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_XIUWEI) {
							m_tb.setText("<mark c=FFBB11>" + "修为：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						} else if (m_prize_list.get(m_index).m_money_type[m_you_index - 1] == Role.CURRENCY_TYPE_ZHANGONG) {
							m_tb.setText("<mark c=FFBB11>" + "战功：" + "</mark>" + m_prize_list.get(m_index).m_money_value[m_you_index - 1]);
						}
						m_lsi.addControls(m_tb);
					} else {
						for (int index = 0; index < m_prize_list.get(m_index).itemsize; index++) {
							m_item_up[index] = new DWGrid(m_cr_down);
							m_item_up[index].m_data = m_prize_list.get(m_index).m_item_list[index];
							m_item_num[index] = new DWTextbox(Integer.toString(m_prize_list.get(m_index).m_item_list[index].m_num));
							final int m_item_index = index;
							m_item_up[index].addListener(new DWListener() {

								public void OnDoubleClick() {
								}

								public void OnClick() {
									Item_infomation(m_item_index);
								}
							});
							if (index % (m_num_2 + 1) == 0) {
								if (index == 0) {
									m_item_up[index].setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 0);
								} else {
									m_item_up[index].setNearAnchor(m_item_up[index - (m_num_2 + 1)], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 5);
								}
							} else {
								m_item_up[index].setNearAnchor(m_item_up[index - 1], Tools.LEFT_TOP, Tools.RIGHT_TOP, 5, 0);
							}
							m_item_num[index].setNearAnchor(m_item_up[index], Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, 0, 0);
							m_item_num[index].setTouch(false);
							m_lsi.addControls(m_item_up[index]);
							m_lsi.addControls(m_item_num[index]);
						}
					}
					m_you_listbox.addSubItem(m_lsi);
				}
			}
		} else {
			for (int i = 0; i < 1 + m_prize_list.get(m_index).moneysize; i++) {
				DWListSubItem m_lsi = new DWListSubItem();
				if (i == 0) {
					DWTextbox m_data_tb = new DWTextbox("<mark c=FFBB11>" + "规则：" + "</mark>" + DWControlTools.CHANGE_ROW + m_prize_list.get(m_index).m_desc + DWControlTools.CHANGE_ROW
							+ "<mark c=55FF00>" + "奖励：" + "</mark>", m_you_listbox.getShowWidth());
					m_data_tb.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
					m_lsi.addControls(m_data_tb);
				} else {
					DWTextbox m_tb = new DWTextbox("<mark c=55FF00>" + "奖励" + "</mark>", m_you_listbox.getShowWidth());
					m_tb.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
					if (m_prize_list.get(m_index).m_money_type[i - 1] == Role.CURRENCY_TYPE_BANGGONG) {
						m_tb.setText("<mark c=FFBB11>" + "帮贡：" + "</mark>" + m_prize_list.get(m_index).m_money_value[i - 1]);
					} else if (m_prize_list.get(m_index).m_money_type[i - 1] == Role.CURRENCY_TYPE_GOLD) {
						m_tb.setText("<mark c=FFBB11>" + "金币：" + "</mark>" + m_prize_list.get(m_index).m_money_value[i - 1]);
					} else if (m_prize_list.get(m_index).m_money_type[i - 1] == Role.CURRENCY_TYPE_JINGHUN) {
						m_tb.setText("<mark c=FFBB11>" + "惊魂：" + "</mark>" + m_prize_list.get(m_index).m_money_value[i - 1]);
					} else if (m_prize_list.get(m_index).m_money_type[i - 1] == Role.CURRENCY_TYPE_RMB) {
						m_tb.setText("<mark c=FFBB11>" + "元宝：" + "</mark>" + m_prize_list.get(m_index).m_money_value[i - 1]);
					} else if (m_prize_list.get(m_index).m_money_type[i - 1] == Role.CURRENCY_TYPE_RONGYU) {
						m_tb.setText("<mark c=FFBB11>" + "荣誉：" + "</mark>" + m_prize_list.get(m_index).m_money_value[i - 1]);
					} else if (m_prize_list.get(m_index).m_money_type[i - 1] == Role.CURRENCY_TYPE_XIUWEI) {
						m_tb.setText("<mark c=FFBB11>" + "修为：" + "</mark>" + m_prize_list.get(m_index).m_money_value[i - 1]);
					} else if (m_prize_list.get(m_index).m_money_type[i - 1] == Role.CURRENCY_TYPE_ZHANGONG) {
						m_tb.setText("<mark c=FFBB11>" + "战功：" + "</mark>" + m_prize_list.get(m_index).m_money_value[i - 1]);
					}
					m_lsi.addControls(m_tb);
				}
				m_you_listbox.addSubItem(m_lsi);
			}
		}
	}

	/**
	 * 指引的方法
	 * @return
	 */
	public DWListSubItem Novice_guide() {
		if (DWControlsManager.getInstance().contains(m_prize_frame) && m_prize_frame != null && m_zuo_listbox != null && m_lsi != null) {
			return m_lsi[0];
		}
		return null;
	}
	public DWButton BackButton()
	{
		if (m_prize_frame != null && DWControlsManager.getInstance().contains(m_prize_frame) && m_but != null) {
			if(m_but.isShow())
			{
				return m_but;
			}
		}
		return null;
	}
	
	public DWImageBox BackImage()
	{
		if (m_prize_frame != null && DWControlsManager.getInstance().contains(m_prize_frame) && m_tuichu != null) {
			return m_tuichu;
		}
		return null;
	}

	public void Update_Money(int m_index) {
		if (m_prize_list.get(m_index).itemsize > 0) {
			m_item_up = new DWGrid[m_prize_list.get(m_index).itemsize];
			m_item_num = new DWTextbox[m_prize_list.get(m_index).itemsize];
			// /取余数
			int m_num_1 = (m_you_listbox.getShowWidth() - 20) % (m_cr_down.getWidth() + 5);
			// 取整数
			int m_num_2 = (m_you_listbox.getShowWidth() - 20) / (m_cr_down.getWidth() + 5);

			if (m_num_1 < m_cr_but.getWidth()) {
				for (int m_you_index = 0; m_you_index < 2; m_you_index++) {
					DWListSubItem m_lsi = new DWListSubItem();
					if (m_you_index == 0) {
						m_data_tb = new DWTextbox("<mark c=FFBB11>" + "规则：" + "</mark>" + DWControlTools.CHANGE_ROW + m_prize_list.get(m_index).m_desc + DWControlTools.CHANGE_ROW + "<mark c=55FF00>"
								+ "奖励：" + "</mark>", m_you_listbox.getShowWidth());
						m_data_tb.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
						m_lsi.addControls(m_data_tb);
					} else {
						for (int index = 0; index < m_prize_list.get(m_index).itemsize; index++) {
							m_item_up[index] = new DWGrid(m_cr_down);
							m_item_up[index].m_data = m_prize_list.get(m_index).m_item_list[index];
							m_item_num[index] = new DWTextbox(Integer.toString(m_prize_list.get(m_index).m_item_list[index].m_num));
							final int m_item_index = index;
							m_item_up[index].addListener(new DWListener() {

								public void OnDoubleClick() {
								}

								public void OnClick() {
									Item_infomation(m_item_index);
								}
							});
							if (index % m_num_2 == 0) {
								if (index == 0) {
									m_item_up[index].setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 0);
								} else {
									m_item_up[index].setNearAnchor(m_item_up[index - m_num_2], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 5);
								}
							} else {
								m_item_up[index].setNearAnchor(m_item_up[index - 1], Tools.LEFT_TOP, Tools.RIGHT_TOP, 5, 0);
							}
							m_item_num[index].setNearAnchor(m_item_up[index], Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, 0, 0);
							m_item_num[index].setTouch(false);
							m_lsi.addControls(m_item_up[index]);
							m_lsi.addControls(m_item_num[index]);
						}
					}
					m_you_listbox.addSubItem(m_lsi);
				}
			} else {
				for (int m_you_index = 0; m_you_index < 2; m_you_index++) {
					DWListSubItem m_lsi = new DWListSubItem();
					if (m_you_index == 0) {
						m_data_tb = new DWTextbox("<mark c=FFBB11>" + "规则：" + "</mark>" + DWControlTools.CHANGE_ROW + m_prize_list.get(m_index).m_desc + DWControlTools.CHANGE_ROW + "<mark c=55FF00>"
								+ "奖励：" + "</mark>", m_you_listbox.getShowWidth());
						m_data_tb.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
						m_lsi.addControls(m_data_tb);
					} else {
						for (int index = 0; index < m_prize_list.get(m_index).itemsize; index++) {
							m_item_up[index] = new DWGrid(m_cr_down);
							m_item_up[index].m_data = m_prize_list.get(m_index).m_item_list[index];
							m_item_num[index] = new DWTextbox(Integer.toString(m_prize_list.get(m_index).m_item_list[index].m_num));
							final int m_item_index = index;
							m_item_up[index].addListener(new DWListener() {

								public void OnDoubleClick() {
								}

								public void OnClick() {
									Item_infomation(m_item_index);
								}
							});
							if (index % (m_num_2 + 1) == 0) {
								if (index == 0) {
									m_item_up[index].setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 0);
								} else {
									m_item_up[index].setNearAnchor(m_item_up[index - (m_num_2 + 1)], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 5);
								}

							} else {
								m_item_up[index].setNearAnchor(m_item_up[index - 1], Tools.LEFT_TOP, Tools.RIGHT_TOP, 5, 0);
							}
							m_item_num[index].setNearAnchor(m_item_up[index], Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, 0, 0);
							m_item_num[index].setTouch(false);
							m_lsi.addControls(m_item_up[index]);
							m_lsi.addControls(m_item_num[index]);
						}
					}
					m_you_listbox.addSubItem(m_lsi);
				}
			}
		} else {
			DWListSubItem m_lsi = new DWListSubItem();
			m_data_tb = new DWTextbox("<mark c=FFBB11>" + "规则：" + "</mark>" + DWControlTools.CHANGE_ROW + m_prize_list.get(m_index).m_desc, m_you_listbox.getShowWidth());
			m_data_tb.setNearAnchor(m_lsi, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
			m_lsi.addControls(m_data_tb);
			m_you_listbox.addSubItem(m_lsi);
		}
	}

	public void Right_Listbox(int index) {
		if (m_you_listbox != null) {
			m_you_listbox.removeAllSubItem();
		}
		if (m_prize_list.get(index).m_desc != null) {
			if (m_prize_list.get(index).moneysize > 0) {
				Update(index);
			} else {
				Update_Money(index);
			}
		} else {
			if (m_prize_list.get(index).moneysize > 0) {
				Update(index);
				m_data_tb.setText("<mark c=55FF00>" + "奖励:" + "</mark>");
			} else {
				if (m_prize_list.get(index).m_item_list.length > 0) {
					Update_Money(index);
					m_data_tb.setText("<mark c=55FF00>" + "奖励:" + "</mark>");
				} else {
					if (m_zuo_listbox != null) {
						m_zuo_listbox.removeAllSubItem();
					}
					if (m_you_listbox != null) {
						m_you_listbox.removeAllSubItem();
					}
					DWListSubItem m_sub_item = new DWListSubItem();
					DWTextbox m_tb = new DWTextbox("<mark c=FFBB11>" + "亲，现在无奖品了哦，继续加油。    └(^o^)┘" + "</mark>", m_you_listbox.getShowWidth());
					m_tb.setNearAnchor(m_sub_item, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
					m_sub_item.addControls(m_tb);
					m_you_listbox.addSubItem(m_sub_item);
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "现在无奖品可领取。");
				}
			}
		}
		if (m_prize_list.get(index).m_timer > 0) {
			timer = m_prize_list.get(index).m_timer;
			m_start_time = System.currentTimeMillis();// 读取时截取系统时间
			m_djs_tb.setText("<mark c=FFBB11>" + "倒计时：" + "</mark>" + "<mark c=FF3300>" + m_prize_list.get(index).m_timer + "</mark>");
			m_djs_tb.setShow(true);
			m_but.setBackground(m_cr_but_1, false);
			m_but.setTouch(false);
		} else {
			m_djs_tb.setShow(false);
			m_but.setBackground(m_cr_but, false);
			m_but.setDownImage(m_cr_but_1);
			m_but.setTouch(true);
		}
	}

	/**
	 * 读取领奖信息
	 */
	byte status;
	long m_timer;
	String key;

	public void recvPrizeMessage(DataInputStream dis) throws IOException {
		status = dis.readByte();// 0 无, 1有领奖
		Tools.debugPrintln("status:" + status);
		if (status == 0) {
			UIWindows.getInstance().m_main.m_imageBox_banjiang.setShow(false);
			UIWindows.getInstance().m_main.m_imageBox_banjiang.setTop(false);
			UIWindows.getInstance().m_main.m_label_banjiang.setShow(false);
		} else if (status == 1) {
			m_timer = dis.readLong();// 倒计时 秒数
			key = dis.readUTF();
			Tools.debugPrintln("m_timer:" + m_timer);
			Tools.debugPrintln("key:" + key);
			if (m_timer > 0) {
				UIWindows.getInstance().m_main.m_label_banjiang.setShow(true);
				UIWindows.getInstance().m_main.m_label_banjiang.setName(Long.toString(m_timer));
				m_start_time = System.currentTimeMillis();
			} else {
				UIWindows.getInstance().m_main.m_label_banjiang.setShow(false);
			}
			

			
			UIWindows.getInstance().m_main.m_imageBox_banjiang.setShow(true);
			UIWindows.getInstance().m_main.m_imageBox_banjiang.setSelect(true);
			UIWindows.getInstance().m_main.m_imageBox_banjiang.setSelectType(DWImageBox.SELECT_TYPE_ARC3);
			UIWindows.getInstance().m_main.m_imageBox_banjiang.setTouch(true);
		}
	}

	public void DJS() {
		if (DWGameManager.getInstance().getGameState() == DWGameManager.GS_GAME) {
			if (m_timer > 0) {
				if (m_start_time == 0) {
					m_start_time = System.currentTimeMillis();// 读取时截取系统时间
				}
				long currentTime = System.currentTimeMillis();// 当前系统时间
				int index = (int) (m_timer - (currentTime - m_start_time) / 1000);
				if (index < 0) {
					m_start_time = 0;
				} else {
					int index_1 = index / 3600;
					int index_2 = index % 3600 / 60;
					int index_3 = index % 3600 % 60;
					if (index_1 != 0) {
						UIWindows.getInstance().m_main.m_label_banjiang.setText("<mark c=FF3300>" + index_1 + "</mark>" + ":" + "<mark c=FF3300>" + index_2 + "</mark>" + ":" + "<mark c=FF3300>"
								+ index_3 + "</mark>");
					} else {
						if (index_2 != 0) {
							UIWindows.getInstance().m_main.m_label_banjiang.setText("<mark c=FF3300>" + index_2 + "</mark>" + ":" + "<mark c=FF3300>" + index_3 + "</mark>");
						} else {
							UIWindows.getInstance().m_main.m_label_banjiang.setText("<mark c=FF3300>" + index_3 + "</mark>");
						}
					}
					UIWindows.getInstance().m_main.m_label_banjiang.setNearAnchor(UIWindows.getInstance().m_main.m_imageBox_banjiang, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 0);
					if (index == 0) {
						m_start_time = 0;
						m_timer = 0;
						UIWindows.getInstance().m_main.m_label_banjiang.setShow(false);
					}
				}
			}
		}
	}

	public CopyOnWriteArrayList<Prize> m_prize_list = new CopyOnWriteArrayList<Prize>();

	/**
	 * 读取领奖列表
	 */
	public boolean m_flag = true;
	int j = 0;
	DWListSubItem m_lsi[] = null;

	public void recvPrizeList(DataInputStream dis) throws IOException {
		byte status = dis.readByte();// 0失败,1成功
		Tools.debugPrintln("状态：" + status);
		if (status == 1) {
			m_prize_list.clear();
			short size = dis.readShort();
			Tools.debugPrintln("奖励长度：" + size);
			if (size > 0) {
				for (short i = 0; i < size; i++) {
					Prize prize = new Prize();
					prize.recvPrize(dis);
					m_prize_list.add(prize);
				}

				if (!DWControlsManager.getInstance().contains(m_prize_frame)) {
					return;
				}
				// //删除左侧的listbox 重置控件及数据
				if (m_zuo_listbox != null) {
					m_zuo_listbox.removeAllSubItem();
				}
				m_list_text = new DWTextbox[size];
				m_lsi = new DWListSubItem[size];
				for (int m_list_index = 0; m_list_index < size; m_list_index++) {
					m_lsi[m_list_index] = new DWListSubItem();
					m_list_text[m_list_index] = new DWTextbox(m_prize_list.get(m_list_index).m_name, m_zuo_listbox.getShowWidth());
					m_list_text[m_list_index].setNearAnchor(m_lsi[m_list_index], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
					final int m_right_index = m_list_index;
					m_list_text[m_list_index].addListener(new DWListener() {
						public void OnDoubleClick() {
						}

						public void OnClick() {
							m_flag = false;
							Right_Listbox(m_right_index);
						}
					});
					m_lsi[m_list_index].addControls(m_list_text[m_list_index]);
					m_zuo_listbox.addSubItem(m_lsi[m_list_index]);
				}

				if (key != null) {
					for (j = 0; j < m_prize_list.size(); j++) {
						if (m_prize_list.get(j).m_key.equals(key)) {
							m_zuo_listbox.setScrollbar(j);
							m_zuo_listbox.setTouchIndex(j);
							key = null;
							break;
						}
					}
				}
				// //删除右侧的listbox 重置控件及数据
				else if (key == null) {
					j = 0;
					m_zuo_listbox.setScrollbar(j);
					m_zuo_listbox.setTouchIndex(j);
				}
				Right_Listbox(j);
				if (m_prize_list.get(j).m_timer > 0) {
					timer = m_prize_list.get(j).m_timer;
					m_start_time = System.currentTimeMillis();// 读取时截取系统时间
					long index_1 = m_prize_list.get(j).m_timer / 3600;
					long index_2 = m_prize_list.get(j).m_timer % 3600 / 60;
					long index_3 = m_prize_list.get(j).m_timer % 3600 % 60;
					m_djs_tb.setShow(true);
					if (index_1 != 0) {
						m_djs_tb.setText("<mark c=FFBB11>" + "倒计时: " + "</mark>" + "<mark c=FF3300>" + index_1 + "</mark>" + ":" + "<mark c=FF3300>" + index_2 + "</mark>" + ":" + "<mark c=FF3300>"
								+ index_3 + "</mark>");
					} else if (index_1 == 0) {
						if (index_2 != 0) {
							m_djs_tb.setText("<mark c=FFBB11>" + "倒计时: " + "</mark>" + "<mark c=FF3300>" + index_2 + "</mark>" + ":" + "<mark c=FF3300>" + index_3 + "</mark>");
						} else {
							m_djs_tb.setText("<mark c=FFBB11>" + "倒计时: " + "</mark>" + "<mark c=FF3300>" + index_3 + "</mark>");
						}
					}
					m_but.setBackground(m_cr_but_1, false);
					m_but.setTouch(false);
				} else {
					m_djs_tb.setShow(false);
					m_but.setShow(true);
					m_but.setBackground(m_cr_but, false);
					m_but.setDownImage(m_cr_but_1);
					m_but.setTouch(true);
				}
			}
		} else if (status == 0) {
			UIWindows.getInstance().m_main.m_imageBox_banjiang.setShow(false);
			UIWindows.getInstance().m_main.m_imageBox_banjiang.setTouch(false);
			UIWindows.getInstance().m_main.m_label_banjiang.setShow(false);
			if (DWControlsManager.getInstance().contains(m_prize_frame)) {
				if (m_zuo_listbox != null) {
					m_zuo_listbox.removeAllSubItem();
				}
				if (m_you_listbox != null) {
					m_you_listbox.removeAllSubItem();
				}
				m_djs_tb.setShow(false);
				m_but.setShow(false);
				m_but.setTouch(false);

				DWListSubItem m_sub_item = new DWListSubItem();
				DWTextbox m_tb = new DWTextbox("<mark c=FFBB11>" + "亲，现在无奖品了哦，继续加油。    └(^o^)┘" + "</mark>", m_you_listbox.getShowWidth());
				m_tb.setNearAnchor(m_sub_item, Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
				m_sub_item.addControls(m_tb);
				m_you_listbox.addSubItem(m_sub_item);
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "现在无奖品可以领取。");
			}
		}
	}

	/**
	 * 读取领奖
	 */
	public void recvPrizeApply(DataInputStream dis) throws IOException {
		byte status = dis.readByte();// 0领取失败,1领取成功
		Tools.debugPrintln("领取奖品成功或者失败，0失败，1成功:" + status);
		if (status == 1) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "奖励领取成功。");
			DWGameManager.getInstance().getSendMessage().sendPrizeList();
		} else if (status == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "抱歉，奖励领取失败。");
		}
	}
}
